import Vue from "vue";
import vueRouter from 'vue-router'
import Home from '../pages/Home'
import List from '../pages/List'
import Music from '../pages/Home/Music'
import Play from '../pages/Home/Play'
import Work from '../pages/Home/Work'
Vue.use(vueRouter)
// push函数存在于VueRouter的实例上,只有在router中才能获取到其实例

// 只是添加了默认值, 使得其不会返回promise对象所以不需要改变原函数
let oldPush = vueRouter.prototype.push
//给函数设置默认值.这样不使用后两项也不会返回promise,从而不会报错了
vueRouter.prototype.push = function (location, onComplete = () => { }, onAbort = () => { }) {
    //  修改this指向,,oldPush为创建的新函数,其中this没有,如果直接使用,会报错
    oldPush.call(this, location, onComplete, onAbort)
}
const route = new vueRouter({
    routes: [
        {
            path: '/home',
            component: Home,
            redirect: "/home/music",
            children: [
                {
                    path: '/home/music',
                    component: Music,
                },
                {
                    path: '/home/play',
                    component: Play,
                    name: 'play'
                },
                {
                    path: '/home/work',
                    component: Work,
                },
            ]
        },
        {
            path: '/list',
            component: List,
        },
    ]
})
export default route